package com.ljx.strategyMode;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;

/**
 *
 * 策略模式练习
 *
 * @作者 LJX
 * @日期 2022/12/22 14:07
 */
public class StrategyPractice {

    public static void main(String[] args) {
//        EnumStrategy normal_10 = EnumStrategy.valueOf("NORMAL_10");
        DiscountStrategy ds = (DiscountStrategy) EnumStrategy.VIP_20.getO();
        BigDecimal bigDecimal = ds.discountStrategy(BigDecimal.valueOf(100));
        System.out.println(bigDecimal.toPlainString());
    }

}

/**
 * 折扣策略
 */
interface DiscountStrategy {

    BigDecimal discountStrategy(BigDecimal bigDecimal);

}

/**
 * 正常打折策略
 */
class NormalDiscountStrategy implements DiscountStrategy {

    //不打折
    @Override
    public BigDecimal discountStrategy(BigDecimal bigDecimal) {
        return bigDecimal;
    }
}

/**
 * VIP打折策略
 */
class VIPDiscountStrategy implements DiscountStrategy {

    //8折
    @Override
    public BigDecimal discountStrategy(BigDecimal bigDecimal) {
        return bigDecimal.multiply(new BigDecimal(0.8d));
    }
}

/**
 * 超级VIP打折策略
 */
class SuperVIPDiscountStrategy implements DiscountStrategy {

    //半价
    @Override
    public BigDecimal discountStrategy(BigDecimal bigDecimal) {
        return bigDecimal.multiply(new BigDecimal(0.5d));
    }
}

/**
 * 用户类型枚举
 */
@Getter
@AllArgsConstructor
enum EnumStrategy{
    NORMAL_10("10", new NormalDiscountStrategy()),
    VIP_20("20", new VIPDiscountStrategy()),
    SUPERVIP_30("30", new SuperVIPDiscountStrategy()),
    ;

    private String userType;

    private Object o;

}

